
<?php 
//print_r($page);

$cs = Yii::app ()->getClientScript (); 
$cs = Yii::app ()->getClientScript()->registerCoreScript ('jquery'); 
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/jquery-ui-1.8.14.custom.min.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/Base.js");



// $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js2/JWidget.js");
// $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js2/JTextWidget.js");
// $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js2/JWeiboWidget.js");
// $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js2/JImageWidget.js");
// $cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js2/JCardWidget.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/colorpicker.js");
//$cs->registerCssFile(Yii::app ()->request->baseUrl. "/css/jui/jquery-ui-1.8.11.custom.css");
$cs->registerCssFile(Yii::app ()->request->baseUrl. "/css/colorpicker/colorpicker.css");
$cs->registerCssFile(Yii::app ()->request->baseUrl. "/css/jwidget.css");


$cs->registerCssFile(Yii::app ()->request->baseUrl. "/css/template/diary.css");


$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/jquery.upload.js"); 
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/json2.js"); 


$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/jsw/JWidget.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/jsw/JTextWidget.js");


$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/jsw/Widget.js");
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/jsw/WidgetPanel.js");

$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/tiny_mce/tiny_mce.js"); 
$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/tiny_mce/jquery.tinymce.js");


//$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/tiny_mce/jquery.tinymce.js");
//$cs->registerScriptFile(Yii::app ()->request->baseUrl. "/js/tiny_mce/tiny_mce.js");

    
 
	 $cs->registerScript('JWidgetOption.saveUrl', "JWidgetOption.saveUrl='".$this->createUrl('/page/save')."';",CClientScript::POS_BEGIN);
	// 	$cs->registerScript('JWidgetOption.baseUrl', "JWidgetOption.baseUrl='".Yii::app()->request->baseUrl."';",CClientScript::POS_BEGIN);
	// 	$cs->registerScript('JImageWidgetOptions.uploadUrl', "JImageWidgetOptions.uploadUrl='".$this->createUrl('/jwidget/image/upload')."';",CClientScript::POS_BEGIN);
	// 	$cs->registerScript('JWidgetOption.bindUrl', "JWidgetOption.bindUrl='".$this->createUrl('/weibo/bind')."';",CClientScript::POS_BEGIN);
	// 	$cs->registerScript('JWidgetOption.saveUrl', "JWidgetOption.saveUrl='".$this->createUrl('/page/edited')."';",CClientScript::POS_BEGIN);
	//      
	//   $cs->registerScript('JWeiboWidgetOption.bindUrl', "JWeiboWidgetOption.bindUrl='".$this->createUrl('/jwidget/weibo/bind')."';",CClientScript::POS_BEGIN);
	// 
	//   $cs->registerScript('JWeiboWidgetOption.bindedUrl', "JWeiboWidgetOption.bindedUrl='".$this->createUrl('/jwidget/weibo/binded')."';",CClientScript::POS_BEGIN);
	// 
	//   $cs->registerScript('JWeiboWidgetOption.showUrl', "JWeiboWidgetOption.showUrl='".$this->createUrl('/jwidget/weibo/show')."';",CClientScript::POS_BEGIN);
	// 
	//   $cs->registerScript('JWeiboWidgetOption.oauthUrl', "JWeiboWidgetOption.oauthUrl='".$this->createUrl('/jwidget/weibo/bindAccount')."';",CClientScript::POS_BEGIN);
	//   $cs->registerScript('JWidgetOption.oauthUrl', "JWidgetOption.oauthUrl='".$this->createUrl('/jwidget/weibo/bindAccount')."';",CClientScript::POS_BEGIN);
	//   
	//   $cs->registerScript('JWeiboWidgetOption.showUrl', "JWeiboWidgetOption.showUrl='".$this->createUrl('/jwidget/weibo/show')."';",CClientScript::POS_BEGIN);
	//   $cs->registerScript('JWidgetOption.showUrl', "JWidgetOption.showUrl='".$this->createUrl('/jwidget/weibo/show')."';",CClientScript::POS_BEGIN);
	//     
	//   $cs->registerScript('JCardWidgetOption.cardShowUrl', "JCardWidgetOption.cardShowUrl='".$this->createUrl('/jwidget/card/show')."';",CClientScript::POS_BEGIN);
	//   $cs->registerScript('JWidgetOption.cardShowUrl', "JWidgetOption.cardShowUrl='".$this->createUrl('/jwidget/card/show')."';",CClientScript::POS_BEGIN);
  
  
  //panel
  $cs->registerScript('JWidgetOption.panelUrl', "JWidgetOption.panelUrl='".$this->createUrl('/jwidget/panel')."';",CClientScript::POS_BEGIN);
  
  $cs->registerScript('JWidgetOption.coreUrl', "JWidgetOption.coreUrl='".$this->createUrl('/jwidget/widget')."';",CClientScript::POS_BEGIN);
             
?>
<?php include  dirname(__FILE__).'/_toolbar.php';?>
<style>
.edit {
	text-align: center;
	top: 50px;
	height:100%;
	  width:80%;
  margin-left:10%;
}

.core-mouseenter{
  border-style:dashed; 
  border-width:1px; 
  border-color:#CC0000;
}
</style>
<div class='edit'/>
<script>
	var wPanel=new WidgetPanel();
<?php 
// $widgets=$page->widgets;
// $widget=$widgets[0];
//echo json_encode($page);


if($page){
	// echo "wPanel.initPageSet(".json_encode($page->widgets).");\n";
	// echo "wPanel.initPageSet(".json_encode($page->widgets).");\n";
	echo "jwidgets=jwidgets.concat(".json_encode($page->widgets).");\n";
		// echo "jwidgets=".json_encode($page).");\n";
		foreach($page->widgets as $widget){
		//$widget->_id = $widget->wid.'';
		// $widget->isEdit = true;
		// echo "jwidgets.push(".json_encode($widget).");\n";
		if($widget['classname']=='Page'){
		echo "wPanel.init(".json_encode($widget).");";
		// break;
		}else{
			echo "var widget=new Widget(".json_encode($widget).",wPanel);";
			echo "widget.load(".json_encode($widget).");";
			// echo "wPanel.add(".json_encode($widget).");";
		}        
	}
}else{
?>
	var rnd=(new Date().getTime()) ^ Math.random();
	var options = {classname:'Page',template:'douban',cntitle:'页面',widget_id:'Page'+rnd,styles : $.extend({},{left:'400px',top:'200px'})};
			var style={
			wid:'Page'+rnd,
			font:"italic bold 12px/20px arial,sans-serif",
			color:'#00ff00',
			width:'150px',
			height:'100px',
			left:'300px',
			top:'200px',
			background: '#00FF00 no-repeat fixed top',
			border:'0px',
			position:'absolute',
			z_index:null,
			opacity:100
			};	 

		var attribute={
			wid:'Page'+rnd,
			weiboId:null,
			bg_pid:null,
			uid:null,
			icon_pid:null,
			text:null,
			template:'douban',
		};
			
		var jwidget={wid:'Page'+rnd,
					 classname:'Page',
					 cntitle:'页面',
					 viewperm:0,
					 cmtperm:0,
					 tranperm:0,
					 trandate:null,
					 orig_wid:null,
					 style:style,
					 attribute:attribute,
					 events:'create'};	
	jwidgets.push(jwidget);	
	wPanel.init(jwidget);
	// wPanel.initPageSet(jwidgets);
<?php }
?>
</script>